<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\common\model\learn\Book;

use cores\BaseModel;

/**
 * 书籍模型
 * Class Category
 * @package app\common\model
 */
class TitleUser extends BaseModel {
	// 定义表名
	protected $name = 'learn_book_user';
	// 定义主键
	protected $pk = 'log_id';
	// 追加字段
	protected $append = ['right_percent'];
	/**
	 * 分类详情
	 * @param int|array $where
	 * @param array $with
	 * @return static|array|null
	 */
	public static function detail($where, array $with = []) {
		return static::get($where, $with);
	}
	public function title() {
		$module = self::getCalledModule();
		return $this->HasOne("app\\{$module}\\model\\learn\\book\\Title", 'subject_id', 'article_id');
	}

	public function getRightPercentAttr($value, $data) {
		$percent = $data['total_num'] > 0 ? $data['right_num'] / $data['total_num'] * 100 : 0;

		$percent = sprintf('%.2f', $percent);
	}

}
